<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8">
    <title>账号列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <!-- load css -->
    <link rel="stylesheet" th:href="@{/css/font.css}" />
	<link rel="stylesheet" th:href="@{/css/xadmin.css}" />
    <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
    <script th:src="@{/js/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
</head>
<body class="layui-anim layui-anim-fadein">
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a>账号管理</a>
        <a><cite>账号列表</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
      <div class="layui-row">
        <div class="layui-form layui-col-md12 x-so">
          <input id="id" type="text" name="id"   placeholder="ID" autocomplete="off" class="layui-input">
          <input id="account" type="text" name="account"  placeholder="账号" autocomplete="off" class="layui-input">
          <div class="layui-input-inline">
            <select id="status" name="status">
              <option value="">禁用状态</option>
              <option value="0">禁用</option>
              <option value="1">正常</option>
            </select>
          </div>
          <div class="layui-input-inline">
            <select id="login_status" name="login_status">
              <option value="">在线状态</option>
              <option value="0">离线</option>
              <option value="1">在线</option>
              <option value="2">异常</option>
              <option value="3">限额</option>
              <option value="4">下单频繁</option>
            </select>
          </div>
          <button id="searchBtn" data-type="reload" class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
          <button class="layui-btn" style="margin-left: 30px;" onclick="downLoadMoban1()">下载账号密码模板</button>
          <button class="layui-btn" style="margin-left: 30px;" onclick="downLoadMoban()">下载CK模板</button>
        </div>
      </div>
      <xblock>
      <button class="layui-btn" onclick="addPage();"><i class="layui-icon"></i>新增CK</button>
      <button class="layui-btn" onclick="addPage2();">账号密码登录</button>
      <button id="batchResetBindFailCount" class="layui-btn">重置绑定次数</button>
      <button id="importData1" class="layui-btn">批量导入账号密码</button>
      <button id="importData" class="layui-btn">批量导入CK</button>
      <button id="removeAll" class="layui-btn" style="float: right;">全部删除</button>
      </xblock>
      <table class="layui-hide" id="table1" lay-filter="tool1"></table>
      <script type="text/html" id="bar1">
		<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="queryOrder">查单</a>
		<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="reLogin">重新登录</a>
		{{#  if(d.status == 1){ }}
 		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">禁用</a>
		{{#  }else{  }}
		<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="del">启用</a>
		{{#  }  }}
		<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="update" onclick="x_admin_show('修改信息','/admin/account/updatePage.html?id={{d.id}}',465,550)">修改</a>
		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="remove">删除</a>
			</script>
      </div>
<script type="text/html" id="statusTpl">
{{#  if(d.status == 1){ }}
<span style="color: green;">正常</span>
{{#  }else{  }}
<span style="color: red;">禁用</span>
{{#  }  }}
</script>
<script type="text/html" id="typeTpl">
{{#  if(d.operator == 'wsgw'){ }}
<span style="color: green;">网上国网</span>
{{#  }else if(d.operator == 'cloud'){  }}
<span style="color: green;">云缴费</span>
{{#  }else if(d.operator == 'weidian'){  }}
<span style="color: green;">微店账号</span>
{{#  }  }}
</script>
<script type="text/html" id="authStatusTpl">
{{#  if(d.auth_status == 1){ }}
<span style="color: green;">已实名</span>
{{#  }else{  }}
<span>未实名</span>
{{#  }  }}
</script>
<script type="text/html" id="loginStatusTpl">
{{#  if(d.login_status == 1){ }}
<span style="color: green;">在线</span>
{{#  }else if(d.login_status == 0){  }}
<span>离线</span>
{{#  }else if(d.login_status == 2){  }}
<span style="color: red;">异常</span>
{{#  }else if(d.login_status == 3){  }}
<span style="color: red;">限额</span>
{{#  }else if(d.login_status == 4){  }}
<span style="color: red;">下单频繁</span>
{{#  }  }}
</script>
<script>
function downLoadMoban()
{
	 window.open('[[@{/doc/导入CK模板.xlsx}]]'); 
}
function downLoadMoban1()
{
	 window.open('[[@{/doc/导入账号模板.xlsx}]]'); 
}
function addPage()
{
	x_admin_show('新增账号','/admin/account/addPage.html?operator=[[${operator}]]',465,550);
}
function addPage2()
{
    x_admin_show('账号密码登录', '/admin/account/loginPage.html?operator=[[${operator}]]', 460, 350);
}
      layui.use(['laydate', 'laypage', 'table', "upload"], function(){
        var laydate = layui.laydate,
        table = layui.table, //表格
        laypage = layui.laypage, //分页
        upload = layui.upload;//主要是这个
        //执行一个 table 实例
        table.render({
          elem: '#table1'
          ,height: 650
          ,limit: 14
          ,limits:[14,20,30,40,50,60,70,80,90]
          ,url: '[[@{/admin/account/list.html?operator=}]]'+ '[[${operator}]]'//数据接口
          ,id:'table1'
          ,page: true
          ,cols: [
           [
            {field: 'id', title: 'ID', width:'5%', sort: true, align:'center',fixed: 'left'}
            ,{field: 'account', title: '账号', width: '8%', align:'center'}
           /*  ,{field: 'quota', title: '充值限额', width: '7%', align:'center'} */
            ,{field: 'auth_status', title: '实名状态', width: '7%',templet:'#authStatusTpl', align:'center'}
            ,{field: 'all_amount', title: '总购买', width: '8%', align:'center'}
            ,{field: 'today_amount', title: '今日购买', width: '8%', align:'center'}
            ,{field: 'buy_count', title: '下单数', width: '8%', align:'center'}
            ,{field: 'type', title: '账号类型', width: '7%',templet:'#typeTpl', align:'center'}
            ,{field: 'login_status', title: '登录状态', width: '7%',templet:'#loginStatusTpl', align:'center'}
            ,{field: 'status', title: '禁用状态', width: '7%',templet:'#statusTpl', align:'center'}
           	,{field: 'remarks', title: '备注',width: '11%', align:'center'}
            ,{fixed: 'right', title: '操作',align:'center', toolbar: '#bar1', width:'23%'}
          ]
          ]
        });
        $('#searchBtn').on('click', function(){
        	var index = layer.msg('查询中，请稍候...',{icon: 16,time:false,shade:0});
        	table.reload('table1', {
    	        page: {
    	          curr: 1 //重新从第 1 页开始
    	        }
    	        ,where: {
    	        	'id': $('#id').val(),
    	            'account':$('#account').val(),
    	            'status': $('#status').val(),
    	            'login_status': $('#login_status').val(),
    	        }
    	      });
        	layer.close(index);
       });
        
        $('#batchResetBindFailCount').on('click', function(){
        	layer.confirm('将重置所有账号的绑定户号次数,确认操作？', function(index){
        		var operator='[[${operator}]]';
                $.post('[[@{/admin/account/batchResetBindFailCount.html}]]',{'operator':operator},function(data){
              	  layer.close(index);
              	  layer.msg(data.msg);
              	  if(data.code==0)
              	  {
              		  table.reload('table1', {
                	        page: {
                	          curr: $(".layui-laypage-em").next().html() //重新从第 1 页开始
                	        }
                	        ,where: {
                	        	'id': $('#id').val(),
                	            'account':$('#account').val(),
                	            'status': $('#status').val(),
                	            'login_status': $('#login_status').val(),
                	        }
                	      });
              	  }
                })
              });
       });
        $('#removeAll').on('click', function(){
        	layer.confirm('将删除所有账号,确认操作？', function(index){
        		var operator='[[${operator}]]';
                $.post('[[@{/admin/account/removeAll.html}]]',{'operator':operator},function(data){
              	  layer.close(index);
              	  layer.msg(data.msg);
              	  if(data.code==0)
              	  {
              		  table.reload('table1', {
                	        page: {
                	          curr: $(".layui-laypage-em").next().html() //重新从第 1 页开始
                	        }
                	        ,where: {
                	        	'id': $('#id').val(),
                	            'account':$('#account').val(),
                	            'status': $('#status').val(),
                	            'login_status': $('#login_status').val(),
                	        }
                	      });
              	  }
                })
              });
       });
        
      //监听工具条
        table.on('tool(tool1)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
          var data = obj.data //获得当前行数据
          ,layEvent = obj.event; //获得 lay-event 对应的值
          if(layEvent === 'queryOrder'){
        	  x_admin_show('查单','/admin/account/onlineOrderListPage.html?id='+data.id,1300,650)
          }
          else if(layEvent === 'reLogin'){
        	  layer.confirm('确认操作？', function(index){
                  $.post('[[@{/admin/account/reLogin.html}]]',{'id':data.id},function(data){
                	  layer.close(index);
                	  layer.msg(data.msg);
                	  if(data.code==0)
                	  {
                		  table.reload('table1', {
                  	        page: {
                  	          curr: $(".layui-laypage-em").next().html() //重新从第 1 页开始
                  	        }
                  	        ,where: {
                  	        	'id': $('#id').val(),
                	            'account':$('#account').val(),
                	            'status': $('#status').val(),
                	            'login_status': $('#login_status').val(),
                  	        }
                  	      });
                	  }
                  })
                  //向服务端发送删除指令
                });
          }
          else if(layEvent === 'del'){
        	  layer.confirm('确认操作？', function(index){
                  $.post('[[@{/admin/account/updateStatus.html}]]',{'id':data.id,'status':data.status},function(data){
                	  layer.close(index);
                	  if(data.code==0)
                	  {
                		  table.reload('table1', {
                  	        page: {
                  	          curr: $(".layui-laypage-em").next().html() //重新从第 1 页开始
                  	        }
                  	        ,where: {
                  	        	'id': $('#id').val(),
                	            'account':$('#account').val(),
                	            'status': $('#status').val(),
                	            'login_status': $('#login_status').val(),
                  	        }
                  	      });
                	  }
                	  else
                	  {
                		  layer.msg('修改失败');
                	  }
                  })
                  //向服务端发送删除指令
                });
          }
          else if(layEvent === 'remove'){
        	  layer.confirm('确认删除?', function(index){
                  $.post('[[@{/admin/account/remove.html}]]',{'id':data.id},function(data){
                	  layer.close(index);
                	  if(data.code==0)
                	  {
                		  table.reload('table1', {
                  	        page: {
                  	          curr: $(".layui-laypage-em").next().html() //重新从第 1 页开始
                  	        }
                  	        ,where: {
                  	        	'id': $('#id').val(),
                	            'account':$('#account').val(),
                	            'status': $('#status').val(),
                	            'login_status': $('#login_status').val(),
                  	        }
                  	      });
                	  }
                	  else
                	  {
                		  layer.msg('删除失败');
                	  }
                  })
                  //向服务端发送删除指令
                });
          }
        });
      
        upload.render({
            elem: "#importData",//导入id
            url: "[[@{/admin/account/importAccountCK.html?operator=}]]"+ "[[${operator}]]",
            accept: "file",
            exts: 'xls|xlsx|xlsm|xlt|xltx|xltm',
            done: function (data) {
          	layer.msg(data.msg);
          	table.reload('table1', {
      	        page: {
      	          curr: $(".layui-laypage-em").next().html() //重新从第 1 页开始
      	        }
      	        ,where: {
      	        	'id': $('#id').val(),
    	            'account':$('#account').val(),
    	            'status': $('#status').val(),
    	            'login_status': $('#login_status').val(),
      	        }
      	      });
            }
        });
        
        upload.render({
            elem: "#importData1",//导入id
            url: "[[@{/admin/account/importAccount.html?operator=}]]"+ "[[${operator}]]",
            accept: "file",
            exts: 'xls|xlsx|xlsm|xlt|xltx|xltm',
            done: function (data) {
          	layer.msg(data.msg);
          	table.reload('table1', {
      	        page: {
      	          curr: $(".layui-laypage-em").next().html() //重新从第 1 页开始
      	        }
      	        ,where: {
      	        	'id': $('#id').val(),
    	            'account':$('#account').val(),
    	            'status': $('#status').val(),
    	            'login_status': $('#login_status').val(),
      	        }
      	      });
            }
        });
      });
    </script>
  </body>
</html>
